<template>
  <div class="role">
    <RoleList @change="handleChangeRole" />
    <div class="role-right">
      <Tabs @change="handleChangeTab" :currentKey="currentComponentKey" />
      <div class="role-right-bottom">
        <KeepAlive>
          <component :is="currentComponent" :roleId="currentRoleId"></component>
        </KeepAlive>
      </div>
    </div>
  </div>
</template>
<script setup>
import { onMounted, ref, shallowRef } from 'vue'
import RoleList from './components/roleList.vue'
import Tabs from './components/tabs.vue'
import UserList from './components/userList.vue'
import Operation from './components/operation.vue'
import Data from './components/data.vue'

const componentConfig = {
  userList: UserList,
  operation: Operation,
  data: Data,
}
const currentComponentKey = ref('')
const currentComponent = shallowRef(null)
const handleChangeTab = (val) => {
  currentComponentKey.value = val
  currentComponent.value = componentConfig[currentComponentKey.value]
}
const currentRoleId = ref('')
const handleChangeRole = (val) => {
  currentRoleId.value = val
}
onMounted(() => {
  handleChangeTab('userList')
})
</script>
<style lang="scss" scoped>
.role {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  &-right {
    flex: 1;
    height: 100%;
    &-bottom {
      width: 100%;
      height: calc(100% - 50px);
      overflow-y: hidden;
    }
  }
}
</style>
